package com.situ.shoplook.common.service.impl;


import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.situ.shoplook.common.dao.BrandDao;
import com.situ.shoplook.common.model.Brand;
import com.situ.shoplook.common.service.BrandService;
import com.situ.shoplook.common.util.PaginateParams;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 功能：
 *
 * @author 千堆雪
 * @version 1.0.0
 * <p>
 * created by 千堆雪 on 2024/8/26, last modified by 千堆雪 on 2024/8/26
 */
@CacheConfig(cacheNames = "com.situ.shoplook.service.impl.BrandServiceImpl")
@Service
public class BrandServiceImpl implements BrandService {
    private BrandDao brandDao;

    @Autowired
    public void setBrandDao(BrandDao brandDao) {
        this.brandDao = brandDao;
    }

    @Override
    public List<Brand> findAll(Brand brand, PaginateParams pp) {
        try (Page<?> __ = PageHelper.startPage(pp.getPageNo(), pp.getPageSize())) {
            return this.brandDao.findAll(brand);
        }
    }

    @Cacheable(keyGenerator = "customKeyGenerator")
    @Override
    public Brand findById(Integer id) {
        return this.brandDao.findById(id);
    }

    @CacheEvict(allEntries = true)
    @Override
    public boolean save(Brand brand) {
        return this.brandDao.save(brand) > 0;
    }

    @CacheEvict(allEntries = true)
    @Override
    public boolean update(Brand brand) {
        return this.brandDao.update(brand) > 0;
    }

    @CacheEvict(allEntries = true)
    @Override
    public int deleteByIds(Integer[] ids) {
        return this.brandDao.deleteByIds(ids);
    }
}
